package edu.cuc.akkaDay01.demo03;

import akka.actor.ActorRef;
import akka.actor.Terminated;
import akka.actor.UntypedActor;

/**
 * Created by bingruiqi on 2017/9/10.
 */
public class WatchActor extends UntypedActor {
    public WatchActor(ActorRef actorRef) {
        getContext().watch(actorRef);
    }

    @Override
    public void onReceive(Object o) throws Exception {
        if (o instanceof Terminated) {
            System.out.println(String.format("%s has terminated ,shutting down ", ((Terminated) o).getActor().path()));
            getContext().system().shutdown();
        } else {
            unhandled(o);
        }
    }

}
